
import java.io.IOException;
import java.lang.reflect.Method;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

public class JavaMethodOOM2 {

	static class OOMMethodObject {
	}

	public static void main(String[] args) throws IOException, ClassNotFoundException {

		int i = 0;
		try {
			while (true) {
				Enhancer enhancer = new Enhancer();
				enhancer.setSuperclass(OOMMethodObject.class);
				enhancer.setUseCache(false);
				enhancer.setCallback(new MethodInterceptor() {
					@Override
					public Object intercept(Object obj, Method method, Object[] paramArr, MethodProxy methodProxy)
							throws Throwable {
						return methodProxy.invokeSuper(obj, paramArr);
					}
				});
				enhancer.create();
				i++;
			}
		} catch (Throwable e) {
			// 5M加载类: 707
			System.out.println("5M加载类: " + i);
			throw e;
		}

	}

}
